from django.db import models
from django.db.models import permalink

from s_te.managers import PublishedManager

import capabilities.models
import tagging

class Page(models.Model):
    """
    A page in the CMS
    """
    author = capabilities.models.UserField()
    title = models.CharField(max_length=100)
    slug = models.SlugField(unique=True)
    body = models.TextField()
    published = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    call_to_action = models.BooleanField(default=True)
    draft = models.BooleanField(default=False)
    
    objects = models.Manager()
    published_objects = PublishedManager() 
    
    class Meta:
        ordering = ['title']
        
    @permalink
    def get_absolute_url(self):
        return ('cm_s_page', [str(self.slug)])
    
    def __unicode__(self):
        return self.title
    
tagging.register(Page)
        
class MainPage(models.Model):
    """
    The main page
    """
    main_page = models.ForeignKey(Page)
